package com.jiepos.mpos.biz.operationlog.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.jiepos.mpos.biz.appInfM.service.OrganizationService;
import com.jiepos.mpos.biz.operationlog.service.FourEleFlowService;
import com.jiepos.mpos.common.entity.App_Log_Four_ElementsEntity;
import com.jiepos.mpos.core.controller.BaseController;
import com.jiepos.mpos.core.entity.Pagination;
import com.jiepos.mpos.core.util.StringUtils;

/**
 * 
 * 四要素流水日志管理
 * @ProjectName:  [mpos] 
 * @Package com.jiepos.mpos.biz.operationlog.controller 
 * @author 张磊
 * @version 1.0
 * @since 2017年10月9日 上午11:46:06
 * @history（历次修订内容、修订人、修订时间等）
 * @UpdateRemark [说明本次修改内容]
 * @Copyright (c) 2017 江苏杰博实信息技术有限公司
 */
@Controller
@RequestMapping("fourEleFlow")
public class FourEleFlowController extends BaseController{
	/** 导出文件名称*/
	private static String EXCEL_FILE_NAME = "四要素验证流水.xls";
	
	@Autowired
	private FourEleFlowService fourEleFlowService;
	@Autowired
	private OrganizationService organizationService;
	
	/**
	 * 获取四要素认证流水页面
	 * @param pagination
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/getfourEleFlowLogList.do")
	public ModelAndView getfourEleFlowLogList(Pagination pagination, HttpServletRequest request,HttpServletResponse response){
		ModelAndView model = new ModelAndView("/module/operationlog/foureleflowlog/foureleflowlog_list");
		model.addObject("appInses", organizationService.getAllAppIns(request));
		return super.getDetail(request, response, model);
	}
	
	/**
	 * 获取四要素认证流水Json
	 * @param request
	 * @param response
	 * @param pagination
	 * @param app_Log_Four_ElementsEntity
	 * @return
	 */
	@RequestMapping("/getfourEleFlowLogListJson.do")
	public Map getfourEleFlowLogListJson(HttpServletRequest request,HttpServletResponse response,Pagination pagination,App_Log_Four_ElementsEntity app_Log_Four_ElementsEntity){
		return fourEleFlowService.getfourEleFlowLogList(pagination,request,app_Log_Four_ElementsEntity);
	}
	
	/**
	 * 文件导出
	 * @param request
	 * @param response
	 * @param app_Log_Four_ElementsEntity
	 */
	@RequestMapping("/exportList.do")
	@ResponseBody
	public void exportList(HttpServletRequest request, HttpServletResponse response, App_Log_Four_ElementsEntity app_Log_Four_ElementsEntity){
		super.clearCookie(request, response);
		String result = fourEleFlowService.exportList(request, EXCEL_FILE_NAME, app_Log_Four_ElementsEntity);
		if (StringUtils.isBlank(result)) {
			super.setFileParam(request, response, EXCEL_FILE_NAME);
		} else {
			super.setErrorFileParam(request, response, result);
		}
	}
}
